﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using HandyControl.Controls;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using SoonCode.FocusTest.Api;
using SoonCode.FocusTest.Events;
using SoonCode.FocusTest.Models;

namespace SoonCode.FocusTest.ViewModels
{
    internal class SelectTeacherViewModel:BindableBase,IDialogAware
    {
        public string Title => "请选择测试老师";
        private string url;
        public string Url
        {
            get { return url;}
            set
            {
                url=value;
                RaisePropertyChanged();
            }
        }
        public ICommand CloseDialogCommand { get; set; }
        
        private IEventAggregator _eventAggregator;

        public event Action<IDialogResult> RequestClose;

        public SelectTeacherViewModel(IEventAggregator aggregator)
        {
            this._eventAggregator=aggregator;
            CloseDialogCommand = new DelegateCommand(() => RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)));
        }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
            
        }

        public void SetSelectTeacher(string name)
        {
            IDialogParameters dialogParameters = new DialogParameters();
            dialogParameters.Add("theater", name);
            RequestClose.Invoke(new DialogResult(ButtonResult.Yes, dialogParameters));
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            string url = API.Host + "#/device/";
            url += "teacher";
            Url = $"{url}?orgId={GlobalModel.Instance.OrgInfo.id}&token={GlobalModel.Token}" ;
        }
    }
}
